<?php $this->_extends(Helper_Store::layout()); ?>
<?php $this->_block('title'); ?> Shopping Cart Checkout - <?=$store['name']?> <?php $this->_endblock(); ?>
<?php $this->_block('contents'); ?>
<?php if(isset($cart['goods'])&&count($cart['goods'])):?>
<div id="MainWrap">

<div class="CartWrap" id="log">
  <div class="CartNav clearfix">
    <div class="floatLeft"><img src="<?=$_BASE_DIR;?>statics/cartnav-step3.gif" alt="购物流程--查看购物车" /></div>
    <div class="floatRight"><img src="<?=$_BASE_DIR;?>statics/cartnav-cart.gif"></div>
  </div>
  	<?php if(isset($error)&&count($error)):?>
	<div class="notice"> 
		<?php foreach($error as $e=>$v):
			switch($e){
				case 'goods': echo 'No Products In cart.<br>'; break;
				case 'payment': echo 'No payment Selected.<br>'; break;
				case 'shipment': echo 'No shipment Selected.<br>'; break;
				case 'ship': echo 'ship addrees or ship method is fail.<br>';break;
				default: echo 'any input is fail.<br>';break;
			}
		 endforeach;?>
	</div>
	<?php endif;?>


  <form method="post" action="" id="order-create" extra="subOrder">
    <div style="display:none">
      <input name="checkForm" type="checkForm" class="_x_ipt checkForm" autocomplete="off" vtype="checkForm" />
    </div>
    <div class="FormWrap" >
      <h3>Shipping Address</h3>
      <div id="receiver">
        <div class="division" id="checkout-recaddr">
          <table width="100%" border="0" cellpadding="0" cellspacing="0" class="liststyle data">
            <col class="span-5" />
            <col />
            <tbody>
			  <tr>
                <th><em style="color:red">*</em> Email：</th>
                <td>
				<input type="text" class="inputstyle _x_ipt" name="email" value="<?=$cart['ship']['email']?>" size="40" /> 
				</td>
              </tr>
			  <tr class="recsave">
                <th> <em style="color:red">*</em>gender：</th>
                <td><input type="radio" name="gender" value="m" <?php if($cart['ship']['gender']=='m'){echo 'checked=true';}?> />Mr  &nbsp;&nbsp; <input type="radio" name="gender" value="f" <?php if($cart['ship']['gender']=='f'){echo 'checked=true';}?> />Ms </td>
              </tr>
			  <tr>
                <th><em style="color:red">*</em> First Name:</th>
                <td><input type="text" name="firstname" value="<?=$cart['ship']['firstname']?>" size="20" />
                    </td>
              </tr>
              <tr>
                <th><em style="color:red">*</em> Last Name:</th>
                <td><input type="text" name="lastname" value="<?=$cart['ship']['lastname']?>" size="20" />
                    </td>
              </tr>
			  <tr>
                <th><em style="color:red">*</em> Phone:</th>
                <td><input type="text" name="phone" value="<?=$cart['ship']['phone']?>" size="20" />
                    </td>
              </tr>
			  <tr>
                <th> Company Name:</th>
                <td><input type="text" name="company" value="<?=$cart['ship']['company']?>" size="20" />
                    </td>
              </tr>
              <tr>
                <th><em style="color:red">*</em> Street Address:</th>
                <td> <input type="text" class="inputstyle _x_ipt" name="street1" value="<?=$cart['ship']['street1']?>" size="40" />
				</td>
              </tr>
			  <tr>
                <th>Street Address 2:</th>
                <td> <input type="text" class="inputstyle _x_ipt" name="street2" value="<?=$cart['ship']['street2']?>" size="40" />
				</td>
              </tr>
              <tr>
                <th><em style="color:red">*</em> Post/Zip Code：</th>
                <td><input type="text" name="postalcode" value="<?=$cart['ship']['postalcode']?>" size="10" /></td>
              </tr>
              
			  
			  
              <tr>
                <th>City：</th>
                <td><input type="text" name="cityname" value="<?=$cart['ship']['cityname']?>" size="20" /></td>
              </tr>
              <tr>
                <th>State/Province：</th>
                <td><input type="text" name="stateorprovince" value="<?=$cart['ship']['stateorprovince']?>" size="20" /></td>
              </tr>
			  <tr>
                <th><em style="color:red">*</em> Country：</th>
                <td id="checkout-select-area"><span package="mainland" class="span _x_ipt" vtype="area">
                  <?php Q::control('dropdownlist','country',array(
        "items"=>$country_array,
        'value'=>$cart['ship']['country']
    ))->display()?>
                </span></td>
              </tr>
              
            </tbody>
          </table>
          <script>window.addEvent('domready',function(){$E('#checkout-select-area input[name^=delivery[]').store('onselect',function(sel){if($E('option[has_c]',sel)){$('shipping').set('html','<div class="notice">请选择收货地区</div>');}});$E('#checkout-select-area input[name^=delivery[]').store('lastsel',function(lastselect){var areaSels=$ES("#checkout-select-area select");var areaSelPrt=areaSels[0].getParent('*[package=mainland]');var selected=[];areaSels.each(function(s){selected.push(s[s.selectedIndex].text);});if(!$('addr').value||$('addr').value==areaSelPrt.retrieve('selectedaddr'))$('addr').value=selected.join('');areaSelPrt.store('selectedaddr',selected.join(''));Cart.checkout.shipping(lastselect);});var areaSels=$ES("#checkout-select-area select");var lastSel=areaSels[areaSels.length-1];if( lastSel.get('value') != '' && lastSel.get('value') != '_NULL_' )lastSel.onchange(lastSel,lastSel.value,(areaSels.length-1));});</script>
        </div>
        <div class="division">
          <table width="100%" border="0" cellpadding="0" cellspacing="0" class="liststyle data">
            <colgroup class="span-5 ColColorGray">
            </colgroup>
            <colgroup class="span-auto">
            </colgroup>
            <tbody>
              <tr>
                <th>  memo ：</th>
                <td colspan="3"><textarea class="inputstyle _x_ipt" name="memo" type="textarea" cols="40" rows="2" vtype="textarea"></textarea></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <h3>Shipping method</h3>
      <div class="division">
        <div class="body" id="shipping">
          	<ul>
				<?php if(count($shipments)) foreach($shipments as $shipment):?>
				<li><input type="radio" name="shipment" value="<?=$shipment->shipment_id?>"   /> <?=$shipment->shipment->title?></li>
				<?php endforeach;?>
			</ul>
        </div>
      </div>
      <h3> Pay method 
	   select currency <?php Q::control('dropdownlist','currency',array(
        "items"=>array('USD'),
        'value'=>$cart['currency']
    ))->display()?>
	  
      </h3>
      <div class="division">
        <div class="body" id="payment">
          <table width="100%" cellpadding="0" cellspacing="0" class="liststyle data" id="_normal_payment">
            <colgroup class="span-5 ColColorGray">
            </colgroup>
            <colgroup class="span-auto">
            </colgroup>
			
			<?php if(count($payments)) foreach($payments as $payment):?>
				<li><input type="radio" name="payment" value="<?=$payment->payment_id?>"  /> <?=$payment->payment->title?></li>
			  <tr id="_pay_cod" style="display:none">
				  <th style="text-align:left;"><input type="radio" name="payment" value="<?=$payment->payment_id?>"  class="x-payMethod" />
					  <strong> <?=$payment->payment->title?></strong></th>
				  <td> <?=$payment->payment->desc?></td>
           	  </tr>
			<?php endforeach;?>
			
          </table>
         
        </div>
      </div>
    
    </div>
    <div class="FormWrap" style="background:#F5F4EC; border:1px solid #E5DDC7;">
      <h3>goods in cart</h3>
      <div class="division">
        <table width="100%" cellpadding="0" cellspacing="0" class="liststyle">
          <colgroup class="span-auto">
          </colgroup>
          <colgroup class="span-2">
          </colgroup>
          <colgroup class="span-2">
          </colgroup>
          <colgroup class="span-3">
          </colgroup>
          <colgroup class="span-2 ColColorOrange">
          </colgroup>
          <thead>
            <tr>
              <th class="product">Name</th>
              <th class="number">price</th>
              <th class="number">Quantity</th>
              <th class="price">Total</th>
            </tr>
          </thead>
          <tbody>
		  <?php $amount=0;
			foreach($goods as $g):
				$sg=$cart['goods'][$g->goods_id];
				$q=$sg['quantity'];
				$total=$q*$g->price;
				$amount+=$total;
			?>
            <tr>
              <td class="product;" style="text-align:left;"><?=$g->title?>
				</td>
              <td class="cost"> <?=Helper_currency::fetch($g->price,$g->currency)?></td>
              <td class="number"><?=$sg['quantity']?></td>
              <td class="cost"><?=Helper_currency::fetch($total,$g->currency)?></td>
            </tr>
			<?php endforeach;?>
          </tbody>
        </table>
      </div>
    </div>
    <div id="amountInfo">
      <table width="100%" cellpadding="0" cellspacing="0" class="liststyle data">
        <col class="span-auto ColColorGray" />
        <tr>
          <td></col></td>
        </tr>
        <col class="span-4 ColColorOrange textright" />
        <tr>
          <td></col></td>
        </tr>
        <tr>
          <th>Product Amout：</th>
          <td value="216" class="price"><?=Helper_currency::fetch($amount)?></td>
        </tr>
        
        <tr>
          <th>Amount：</th>
          <td><span class="price1"><?=Helper_currency::fetch($amount)?></span></td>
        </tr>
      </table>
    </div>
    <div class="CartBtn clearfix">
      <input type="hidden" name="fromCart" value="true" />
      <div class="span-auto">
        <input name="button"  type="button" class="actbtn btn-return-checkout" onClick="history.back()" value="Return" />
      </div>
      <div class="span-auto floatRight last">
        <input name="submit" type="submit" class="actbtn btn-order" value=" Confirm " />
      </div>
    </div>
  </form>
  
</div>
<?php else:?>
<p id="cart-none-msg">
<div class="notice">
	No Products in cart !
</div>
<h3>Now You can:</h3>
<ul class='list'><li><a href='<?=url('')?>'>Return Home</a></li><li><a href='javascript:opener=null;window.close();'>Close</a></li></ul>
</p>
<?php endif;?>
<?php $this->_endblock('contents'); ?>
